<template>
  <div class="dashboard">
    <div class="box-dashboard-el box-active-dashboard-el">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="订单及金额统计" name="dashboard-third"></el-tab-pane>
      </el-tabs>
    </div>
    <p />
    <!--订单及金额统计-->
    <statics-card
      id="tab-dashboard-third-detail"
      title="订单及金额统计（元）"
      ref="scAmountAndCount"
      v-model="amountAndCount"
      :apiFunc="()=>statementApi.getTimeOrderMoney(startDate4AmountAndCount,endDate4AmountAndCount)"
    >
      <template v-slot:data>
        <ChartLineOrderMoney
          :amountAndCount="amountAndCount"
          @changeDate="(args)=>{startDate4AmountAndCount=args.startDateStr;endDate4AmountAndCount=args.endDateStr;$refs.scAmountAndCount.refresh()}"
        ></ChartLineOrderMoney>
      </template>
    </statics-card>
    <p />
    <!--报修统计-->
  </div>
</template>

<script>
import statementApi from '@/api/statement'
import StaticsCard from '@/components/dashboard/statics-card'
import ChartLineOrderMoney from '@/components/dashboard/chart-line-ordermoney'
export default {
  name: 'dashboard',
  components: {
    StaticsCard,
    ChartLineOrderMoney
  },
  methods: {
    /**
     * tab跳转
     */
    handleClick (tab, event) {
      document
        .getElementById(event.target.getAttribute('id') + '-detail')
        .scrollIntoView(true)
    },
    /**
     * 时间转换工具
     */
    _dateToStr (d) {
      return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`
    },
    /**
     * 时间转换工具
     */
    _dateToDayStr (d) {
      return `${d.getMonth() + 1}-${d.getDate()}`
    },
    /**
     * 数字加逗号分隔符
     *
     */
    numFormat (num) {
      num = num.toString().split('.') // 分隔小数点
      var arr = num[0].split('').reverse() // 转换成字符数组并且倒序排列
      var res = []
      for (var i = 0, len = arr.length; i < len; i++) {
        if (i % 3 === 0 && i !== 0) {
          res.push(',') // 添加分隔符
        }
        res.push(arr[i])
      }
      res.reverse() // 再次倒序成为正确的顺序
      if (num[1]) {
        // 如果有小数的话添加小数部分
        res = res.join('').concat('.' + num[1])
      } else {
        res = res.join('')
      }
      return res
    }
  },
  data () {
    return {
      statementApi,
      activeName: 'dashboard-third', // 默认选中第一个tab
      label: {
        offset: 30,
        rotate: -45,
        autoRotate: false
      },
      height: 400,
      style: { stroke: '#fff', lineWidth: 1 },
      data: [],
      deviceCount: {
        totalCount: 0,
        activeCount: 0,
        noneActiveCount: 0,
        errorCount: 0,
        offlineCount: 0,
        recentlyExpireCount: 0,
        expiredCount: 0
      },
      agentCount: {
        totalCount: 0,
        activeCount: 0,
        recentlyExpireCount: 0,
        expiredCount: 0
      },
      amountAndCount: {
        datas: [],
        orderTotalMoney: 0,
        orderTotalAmount: 0
      },
      userCount: {
        datas: [],
        userTotal: 0
      },
      repairTop10: [],
      startDate4AmountAndCount:
        this._dateToStr(
          new Date(new Date().getTime() - 6 * 24 * 60 * 60 * 1000)
        ) + ' 00:00:00',
      endDate4AmountAndCount: this._dateToStr(new Date()) + ' 23:59:59'
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.dashboard {
  padding: 10px,10px,0px;
  &-container {
    margin-top: 30px;
  }
  &-text {
    font-size: 30px;
    line-height: 46px;
  }
}
.box-dashboard-el {
  position: relative;
  margin-top: 60px;
  height: 80px;
  width: 80%;
  z-index: 999;
}
.box-active-dashboard-el {
  position: fixed;
  top: 0;
}
.custom-tooltip-item-device-r1 {
  width: 200px;
  border-left: 8px solid #1890ff;
  margin: 10px;
  font-weight: bold;
  &:nth-child(2) {
    border-left-color: #f0ec09;
  }
  &:nth-child(3) {
    border-left-color: #0aaf41;
  }
  &:nth-child(4) {
    border-left-color: #fa1414;
  }
}
.custom-tooltip-item-device-r2 {
  width: 200px;
  border-left: 8px solid #b3b1ac;
  margin: 10px;
  font-weight: bold;
  &:nth-child(2) {
    border-left-color: #e0e40f;
  }
  &:last-child {
    border-left-color: #948f8f;
  }
}
.custom-tooltip-item-agent {
  width: 200px;
  border-left: 8px solid #1890ff;
  margin: 10px;
  font-weight: bold;
  &:nth-child(2) {
    border-left-color: #f0ec09;
  }
  &:nth-child(3) {
    border-left-color: #0aaf41;
  }
  &:last-child {
    border-left-color: #f30c0c;
  }
}
.custom-tooltip-item-name {
  line-height: 20px;
  color: rgba(0, 0, 0, 0.45);
  font-size: 14px;
}
.custom-tooltip-item-value {
  line-height: 30px;
  color: #262626;
  font-size: 22px;
}
</style>
